<template>
	<view class="container">
		<scroll-view class="scroll_view" scroll-y="true" scroll-with-animation="true">
			<view class="item_content">
				<uni-card padding="0" spacing="0" @click="itemclick(aritcle)" margin="30"
					v-for="aritcle in article_list" :key="aritcle.info_id">
					<view class="item_card">
						<view class="item_card_box">
							<view>
								<text class="item_card_title">{{aritcle.title}}</text>
							</view>
							<view>
								<text class="item_card_author">{{aritcle.article_from}}</text>
							</view>
							<view class="item_card_text">
								<text class="uni-body uni-mt-5">{{aritcle.summery}}</text>
							</view>
						</view>
						<view class="item-arrow">
							<image style="width: 17rpx;height: 30rpx; margin-right: 30rpx;" src="/static/image/jt.png">
							</image>
						</view>
					</view>
				</uni-card>
			</view>

			<uni-section title="" type="line">
				<uni-load-more iconType="auto" :status="status" />
			</uni-section>

		</scroll-view>


	</view>
</template>

<script>
	import api from './article_list.js'
	export default {
		data() {
			return {
				theme: {},
				article_list: [],
				screenHeight: "800",
				page: 1,
				status: 'more',
			}
		},
		onLoad(option) {
			let themeJson = decodeURIComponent(option.theme);
			this.theme = JSON.parse(themeJson);
			this.screenHeight = uni.getSystemInfoSync().windowHeight

			uni.setNavigationBarTitle({
				title: this.theme.subject,
			});
			
			this.share.title=this.theme.subject;
			this.share.path='/pages/article_list/article_list?theme=' + encodeURIComponent(JSON.stringify(this.theme))
			// 微信小程序分享功能
			uni.showShareMenu({
				withShareTicket:true,
				menus: ["shareAppMessage", "shareTimeline"] //不设置默认发送给朋友
			})
		},
		onReady() {
			this.getArticleList();
		},

		onReachBottom() {
			this.loadMore();
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			itemclick(article) {
				//传的是对像，转成json字符串;
				uni.navigateTo({
					url: '/pages/article/article?article=' + encodeURIComponent(JSON.stringify(article))
				})
			},
			loadMore() {
				if (this.article_list.length == this.page * 10) {
					this.page++;
					this.getArticleList();
				}
			},
			async getArticleList() {
				this.status = 'loading';
				let res = await api.getArticleList(this.theme.node_id, this.page);
				let data_list = res.data.data;
				for (let i = 0; i < data_list.length; i++) {
					data_list[i].summery = data_list[i].summery.replaceAll("\n", "");
				}

				this.article_list = [...this.article_list, ...data_list];
				if (res.data.data.length == 10) {
					this.status = 'more';
				} else {
					this.status = 'no-more';
				}
			},

		}
	}
</script>

<style lang="scss">
	@import "@/common/title_bar.css";
	@import "./article_list.scss";
</style>
